//
//  OBDCommand.swift
//  OBD
//
//  Created by sqkj on 2021/11/11.
//

import Foundation

enum vehicle_protocol: Int64 {
    //MARK:- 车辆命令
    case OTP = 0x0002 //车外温度
    case BP = 0x0005 //电池电压
    case SPD = 0x000B //车速
    case RPM = 0x000C //转速
    case TIME = 0x000D //当前系统计时
    case DC = 0x0011 //故障码
    case ODO = 0x0012 //总里程
    case DR = 0x0013 //本次行驶里程
    case LPK = 0x0014 //瞬时油耗
    case TRIP = 0x0015 //行程数据
    case CTS = 0x0016 //冷却液温度
    case CLV = 0x0017 //计算负荷值
    case ECUPT = 0x0018 //ECU 通信协议
    case ECUDATA = 0x0019 //ECU 诊断数据
    case DCCOUNT = 0x001B //故障码总数
    case VVTTIME = 0x001D //发动机运行时长
    case TPSPT = 0x001E //节气门绝对位置
    case IATS = 0x001F //进气温度
    case APSP = 0x003C //相对油门踏板位置
    case VIN = 0x0020 //车架号
    case AHU = 0x0001 //车内温度
    case FUEL_FELT = 0x0003  //剩余油量
    case CONTIUE_MILAGE =  0x0004 //续航里程
    case LOCK = 0x0006 //车锁
    case DOOR = 0x0007 //车门
    case WINDOW = 0x0008 //车窗
    case GEAR = 0x0009 //档位
    case PULL = 0x000A //手刹
    case LIGHT1 = 0x000E //灯状态 1
    case LIGHT2 = 0x000F //灯状态 2
    case WHEEL_CR = 0x0010 //方向盘转向角
    case GYRO = 0x001A //陀螺仪参数
    case TIRE_PRE = 0x001C //胎压
    case HORN = 0x0024 //喇叭
    case ACC = 0x0025 //ACC 状态
    case ENGINE = 0x0026 //发动机状态
    case KEY_PT = 0x0027 //机械钥匙位置
    case KEY_STATUS = 0x0028 //遥控钥匙状态
    case PULL_STATUS = 0x0029 //脚刹状态
    case NOWTIME = 0x0030 //当前时间
    case PEDAL = 0x002A //油门踏板
    case CLUTCH = 0x002B// 离合状态
    case AIR = 0x002C //空调状态
    case WIPER = 0x002D //雨刮状态
    case SAFE_BAG = 0x002E //安全气囊状态
    case LOC = 0x002F //经纬度
}

enum operation_protocol: Int64  {
    case REPROT_REALTIME_DATA = 0x0F0C // 上报车辆实时参数
    case BLUETOOTH_HAND = 0x0006 // 蓝牙握手
    case SPEED_TEST = 0x0021 // 速度测试
    case DISTANCE_TEST = 0x0022 // 定距测试
    case PULL_TEST = 0x0023 //刹车测试
}

enum device_protocol: Int64 {
    //MARK:- 终端参数设置各参数
    case DEVICE_PARM_SN = 0xF000 //终端 SN
    case DEVICE_PARM_VESION = 0xF001 //硬件版本
    case DEVICE_PARM_BOOT_VESION = 0xF002 //BOOT 版本
    case DEVICE_PARM_BOOT_DATE = 0xF003 //编译日期
    case DEVICE_PARM_FMW_NAME = 0xF004
    case DEVICE_PARM_FMW_VESION_RELEASE = 0xF005
    case DEVICE_PARM_FMW_VESION_DEBUG = 0xF006
    case DEVICE_PARM_FMW_LANG = 0xF007
    case DEVICE_PARM_FMW_SIZE = 0xF008
    case DEVICE_PARM_FMW_CONENT = 0xF009
    case DEVICE_PARM_FMW_LENGTH = 0xF00A
    case DEVICE_PARM_FMW_START_PAGE = 0xF00B
    case DEVICE_PARM_FMW_MD5 = 0xF00C
    case DEVICE_PARM_FMW_BULD_DATE = 0xF00D
    case DEVICE_PARM_MCUID = 0xF00E
    case DEVICE_PARM_PD_DATE = 0xF00F
    case DEVICE_PARM_MFRS_ID = 0xF010
    case DEVICE_PARM_SYS_TIME = 0xF011
    case DEVICE_PARM_RS_QC = 0xF012
    case DEVICE_PARM_PD_STATUS = 0xF013
    case DEVICE_PARM_RAN = 0xF014
    case DEVICE_PARM_RUN_MODE = 0xF015
    case DEVICE_PARM_ACF_CODE = 0xF016
    case DEVICE_PARM_HAND_PWD = 0xF017
    case DEVICE_PARM_VEH_VINE = 0xF201
    case DEVICE_PARM_VEH_BRAND = 0xF202
    case DEVICE_PARM_VEH_MODEL = 0xF203
    case DEVICE_PARM_VEH_YEAR = 0xF204
    case DEVICE_PARM_VEH_EMISSION = 0xF205
    case DEVICE_PARM_VEH_LICENSE = 0xF206
    case DEVICE_PARM_VEH_MILEAGE = 0xF207
    case DEVICE_PARM_VEH_FUEL = 0xF208
    case DEVICE_PARM_VEH_AHU = 0xF209
    
    //MARK:- 终端控制参数
    case DEVICE_CONTROL_PARM_COLSE = 0x0001
    case DEVICE_CONTROL_PARM_REBOOT = 0x0002
    case DEVICE_CONTROL_PARM_QC = 0x0003
    case DEVICE_CONTROL_PARM_DFRESET = 0x0004
    case DEVICE_CONTROL_PARM_RUN_MODE = 0x0005
    case DEVICE_CONTROL_PARM_LOCK = 0x0006 //车锁
    case DEVICE_CONTROL_PARM_DOOR = 0x0007 //车门
    case DEVICE_CONTROL_PARM_FLASH = 0x000E //双闪
    case DEVICE_CONTROL_PARM_LIGHT = 0x000F //车灯
    case DEVICE_CONTROL_PARM_DC = 0x0011 //故障码
    case DEVICE_CONTROL_PARM_ECU = 0x0019 //ECU 诊断数据
    case DEVICE_CONTROL_PARM_VIN = 0x0020 //车架号
    case DEVICE_CONTROL_PARM_SPEED = 0x0021 //速度测试
    case DEVICE_CONTROL_PARM_DISTANCE = 0x0022 //定距测试
    case DEVICE_CONTROL_PARM_PULL = 0x0023 //刹车测试
    case DEVICE_CONTROL_PARM_HORN = 0x0024 //喇叭
    case DEVICE_CONTROL_PARM_ENGINE = 0x0026 //发动机
    case DEVICE_CONTROL_PARM_AIR = 0x002C //空调
}

enum vehicle_type {
    case VIN //车辆车架号
    case BRAND  //车辆品牌(代码)
    case MODEL  //车辆型号
    case YEAR  //车辆年款
    case EMISSION  //车辆排量
    case LICENSE  //车牌号
    case MILEAGE  //总里程
    case FUEL  //油耗起计里程
    
    var setParamValue:[UInt8]{
        switch self {
        case .VIN: return [0xF2,0x01]
        case .BRAND:return  [0xF2,0x02]
        case .MODEL:return [0xF2,0x03]
        case .YEAR:return [0xF2,0x04]
        case .EMISSION:return [0xF2,0x05]
        case .LICENSE:return [0xF2,0x06]
        case .MILEAGE:return [0xF2,0x07]
        case .FUEL:return [0xF2,0x08]
        }
    }
}

enum response_protocol: Int64 {
    case DEVICE_COMMON_RESP                            = 0x0001  // 终端通用应答
    case APP_COMMON_RESP                               = 0x8001  // 平台通用应答
    case DEVICE_COMMON_RESP_SET                        = 0x8F03  // 设置终端参数
    case DEVICE_COMMON_RESP_QUERY_PARAM                = 0x8F06  // 查询终端指定参数
    case DEVICE_COMMON_RESP_DEVICE_QUERY               = 0x0F05  // 查询终端参数应答
    case DEVICE_COMMON_RESP_CONTROL                    = 0x8F04  // 终端控制
    case DEVICE_COMMON_RESP_UPDATE_PROPERTY_MESSAGE    = 0x8F07  // 下发终端升级包属性信息
    case DEVICE_COMMON_RESP_UPDATE_DATA                = 0x8F08  // 下发终端升级包数据
    case DEVICE_COMMON_RESP_QUERY_CAR_PARAM            = 0x8F0B  // 查询车辆指定参数
    case DEVICE_COMMON_RESP_VHE_QUERY                  = 0x0F0A  // 查询车辆参数应答
    case DEVICE_COMMON_RESP_CAR_CONTROL                = 0x8F09  // 车辆控制
    case DEVICE_COMMON_RESP_REALTIME                 = 0x0F0C  // 上报车辆实时参数
    case DEVICE_COMMON_RESP_UPDATE_PACAGE_INPUT_RESULT = 0x0F0F  // 上传升级包烧录结果
}

enum error_protocol : Int64 {
    case COMMON_RESP_SUCESS = 0 //成功/确认
    case COMMON_RESP_FAIL = 1 //一般失败
    case COMMON_RESP_MSG_ERR = 2 //消息有误
    case COMMON_RESP_FUNCTION_NO = 3 //功能不支持
    case COMMON_RESP_WARN_CONFIRM = 4 //报警处理确认
    case COMMON_RESP_RUN_BUSY = 5 //运行繁忙
    case COMMON_RESP_TIMEOUT = 6 //超时
    case COMMON_RESP_TR_ERR = 7 //通讯错误
    case COMMON_RESP_ECU_NO = 8 //ECU 否定回答
    case COMMON_RESP_INX_EX = 9 //下标越界，存在溢出等
    case COMMON_RESP_SYS_NULL = 10 //系统不存在
    case COMMON_RESP_PARAM_ERR = 11 //参数错误/非法
    case COMMON_RESP_DATA_CONTENT_ERR = 12 //数据内容错误
    case COMMON_RESP_DATA_LENGTH_LACK = 13 //数据长度不够
    case COMMON_RESP_DATA_LENGTH_FULL = 14 //数据长度过长
    case COMMON_RESP_MERROY_FAIL = 15 //内存分配失败
    case COMMON_RESP_ENVIR_NO = 16 //当前环境/条件不支持
    case COMMON_RESP_RUN_NOW = 17 //程序正在运行中
    case COMMON_RESP_ECU_TR_FAIL = 18 //与车辆 ECU 之间的通信失败
    case COMMON_RESP_HANDCONNECT_FAIL = 19 //蓝牙握手失败
}

enum carbrand_protocol :Int64{
    case GM = 0x10
    case FORD = 0x11
    case CHRYSLER = 0x12
    case TESLA = 0x13
    case ABARTH = 0x20
    case ALFA_ROMEO = 0x21
    case AUDI = 0x22
    case BMW = 0x23
    case PORSCHE = 0x24
    case BENZ = 0x25
    case PEUGEOT = 0x26
    case BENTLEY = 0x27
    case BUGATTI = 0x28
    case DACIA = 0x29
    case VW = 0x2A
    case FERRARI = 0x2B
    case FIAT = 0x2C
    case JAGUAR = 0x2D
    case LAMBORGHINI = 0x2E
    case LANCIA = 0x2F
    case ROLLS_ROYCE = 0x30
    case RENAULT = 0x31
    case SPRINTER = 0x32
    case LAND_ROVER = 0x33
    case MASERATI = 0x34
    case MAYBACH = 0x35
    case OPEL = 0x36
    case SAAB = 0x37
    case SKODA = 0x38
    case VOLOV = 0x39
    case VAUXHALL = 0x3A
    case SEAT = 0x3B
    case CITROEN = 0x3C
    case MINI = 0x3D
    case SMART = 0x3E
    case ASTON_MARTIN = 0x3F
    case HONDA = 0x50
    case DAIHATSU = 0x51
    case TOYOTA = 0x52
    case LEXUS = 0x53
    case SUZUKI = 0x54
    case MAZDA = 0x55
    case ACURA = 0x56
    case NISSAN = 0x57
    case SCION = 0x58
    case MITSUBISHI = 0x59
    case SSANGYONG = 0x5A
    case SUBARU = 0x5B
    case ISUZU = 0x5C
    case INFINITI = 0x5D
    case HYUNDAI = 0x70
    case KIA = 0x71
    case DAEWOO = 0x72
    case RNSAMSUNG = 0x73
    case PERODUA = 0x7A
    case PROTON = 0x7B
    case UNKOWNED = 0x00
    
    var band:(carbrand_protocol,String){
        switch self {
        case .GM: return (self,"通用")
        case .FORD: return (self,"福特")
        case .CHRYSLER: return (self,"克莱斯勒")
        case .TESLA: return (self,"特斯拉")
        case .ABARTH: return (self,"阿巴斯")
        case .ALFA_ROMEO: return(self, "阿尔法罗密欧")
        case .AUDI: return (self, "奥迪")
        case .BMW: return (self, "宝马")
        case .PORSCHE: return (self, "保时捷")
        case .DACIA:
            return (self, "达西亚")
        case .VW:
            return (self, "大众")
        case .FERRARI:
            return (self, "法拉利")
        case .FIAT:
            return (self, "菲亚特")
        case .JAGUAR:
            return (self, "捷豹")
        case .LAMBORGHINI:
            return (self, "兰博基尼")
        case .LANCIA:
            return (self, "蓝西亚")
        case .ROLLS_ROYCE:
            return (self, "劳斯莱斯")
        case .RENAULT:
            return (self, "雷诺")
        case .SPRINTER:
            return (self, "凌特")
        case .LAND_ROVER:
            return (self, "路虎")
        case .MASERATI:
            return (self, "玛莎拉蒂")
        case .MAYBACH:
            return (self, "迈巴赫")
        case .OPEL:
            return (self, "欧宝")
        case .SAAB:
            return (self, "绅宝")
        case .SKODA:
            return (self, "斯柯达")
        case .VOLOV:
            return (self, "沃尔沃")
        case .VAUXHALL:
            return (self, "沃克斯豪尔")
        case .SEAT:
            return (self, "西亚特")
        case .CITROEN:
            return (self, "雪铁龙")
        case .MINI:
            return (self, "MINI")
        case .SMART:
            return (self, "SMART")
        case .ASTON_MARTIN:
            return (self, "阿斯顿马丁")
        case .HONDA:
            return (self, "本田")
        case .DAIHATSU:
            return (self, "大发")
        case .TOYOTA:
            return (self, "丰田")
        case .LEXUS:
            return (self, "雷克萨斯")
        case .SUZUKI:
            return (self, "铃木")
        case .MAZDA:
            return (self, "马自达")
        case .ACURA:
            return (self, "讴歌")
        case .NISSAN:
            return (self, "日产")
        case .SCION:
            return (self, "赛恩")
        case .MITSUBISHI:
            return (self, "三菱")
        case .SSANGYONG:
            return (self, "双龙")
        case .SUBARU:
            return (self, "斯巴鲁")
        case .ISUZU:
            return (self, "五十铃")
        case .INFINITI:
            return (self, "英菲尼迪")
        case .HYUNDAI:
            return (self, "现代")
        case .KIA:
            return (self, "起亚")
        case .DAEWOO:
            return (self, "大宇")
        case .RNSAMSUNG:
            return (self, "雷诺-三星")
        case .PERODUA:
            return (self, "PERODUA")
        case .PROTON:
            return (self, "宝腾")
        case .BENZ:
            return (self, "奔驰")
        case .PEUGEOT:
            return (self, "标致")
        case .BENTLEY:
            return (self, "宾利")
        case .BUGATTI:
            return (self, "布加迪")
        case .UNKOWNED:
            return (self, "未知")
        }
    }
}
